<%-- 
    Document   : form_dangky
    Created on : 17-10-2011, 20:18:47
    Author     : VuTienIT
--%>
<%@page import="java.util.ArrayList" %>
<%@page import="model.pojo.*" %>
<%@page import="net.tanesha.recaptcha.ReCaptcha" %>
<%@page import="net.tanesha.recaptcha.ReCaptchaFactory" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
KhachHangPOJO kh = new KhachHangPOJO();
if(request.getAttribute("tt-kh")==null)
{
    kh = new KhachHangPOJO();
    request.setAttribute("KhachHang", kh);
}
else
{
    kh = (KhachHangPOJO) request.getAttribute("tt-kh");
}
%>

<!DOCTYPE html>
<script language="javascript">
function checkEmail(email){
   re=/^(([a-zA-Z0-9])+\.?)*([a-zA-Z0-9])+@(([a-zA-Z0-9])+\.)+[a-zA-Z]{2,4}$/;
   if(!re.test(email.value)){alert("Email của bạn không hợp lệ.");return false;}
   return true;
}
function checkPhone(phone){
   re=/^[0-9]{1,11}$/;
   if(!re.test(phone.value)){alert("Số điện thoại của bạn không hợp lệ.");return false;}
   return true;
}
function checkForm(f){   
   if(!checkEmail(f.email)){f.email.focus();return false;}
   if(f.tentaikhoan.value.trim() == ""){alert('Tên tài khoản không được bỏ trống');   f.tentaikhoan.focus();return false;}
   if(f.matkhau.value.trim() == ""){alert('Mật khẩu không được bỏ trống');   f.matkhau.focus();return false;}
   if(f.matkhau.value.trim() != f.golaimatkhau.value.trim()){alert('Mật khẩu xác nhận không đúng');   f.golaimatkhau.focus();return false;}
   if(f.thanhpho.value.trim() == ""){alert('Vui lòng chọn khu vực');      f.thanhpho.focus();return false;} 
   if(!checkPhone(f.sodienthoai)){f.sodienthoai.focus();return false;}
}
function checkField(field,name){
   if(field.value == ""){
      alert(name + ' không được bỏ trống');
      field.focus();
   }
}
</script>
<div id="content_middle">
    <h3>Đăng ký</h3>
<div class="detail_box">
  <div class="sidebar_box_content">
      <div id="login_box">
<form id="form1" name="form1" method="post" action="DangKy?Action=Reg">
  <table width="100%" border="0">
    <tr>
      <td width="20%">Email</td>
      <td width="80%" align="left"><label>
      <input type="text" name="email" id="email" value="<%if(kh.getEmail()!=null){out.println(kh.getEmail());}%>" />
      </label></td>
    </tr>
    <tr>
      <td width="20%">&nbsp;</td>
      <td width="80%" align="left" class="style2">
          <%
            if (request.getAttribute("Error_Email") != null) {
                out.println(request.getAttribute("Error_Email"));
            }
            %>
      </td>
    </tr>
    <tr>
      <td width="20%">Tên tài khoản</td>
      <td width="80%" align="left"><label>
        <input type="text" name="tentaikhoan" id="tentaikhoan" value="<%if(kh.getTenTruyCap()!=null){out.println(kh.getTenTruyCap());}%>" />
      </label></td>
    </tr>
    <tr>
      <td width="20%">&nbsp;</td>
      <td width="80%" align="left" class="style2">
          <%
            if (request.getAttribute("Error_TenDN") != null) {
                out.println(request.getAttribute("Error_TenDN"));
            }
            %>
      </td>
    </tr>
    <tr>
      <td width="20%">Mật khẩu</td>
      <td width="80%" align="left"><label>
        <input type="password" name="matkhau" id="matkhau" value="" />
      </label></td>
    </tr>
    <tr>
      <td width="20%">&nbsp;</td>
      <td width="80%" align="left" class="style2">
          <%
            if (request.getAttribute("Error_MatKhau") != null) {
                out.println(request.getAttribute("Error_MatKhau"));
            }
            %>
      </td>
    </tr>
    <tr>
      <td width="20%">Gõ lại mật khẩu</td>
      <td width="80%" align="left"><label>
        <input type="password" name="golaimatkhau" id="golaimatkhau" value="" />
      </label></td>
    </tr>
    <tr>
      <td width="20%">&nbsp;</td>
      <td width="80%" align="left" class="style2">
          <%
            if (request.getAttribute("Error_MatKhauRe") != null) {
                out.println(request.getAttribute("Error_MatKhauRe"));
            }
            %>
      </td>
    </tr>
    <tr>
      <td width="20%">Số điện thoại</td>
      <td width="80%" align="left"><label>
        <input type="text" name="sodienthoai" id="sodienthoai" value="<%if(kh.getSoDienThoai()!=null){out.println(kh.getSoDienThoai());}%>" />
      </label></td>
    </tr>
    <tr>
      <td width="20%">&nbsp;</td>
      <td width="80%" align="left" class="style2">
          <%
            if (request.getAttribute("Error_DT") != null) {
                out.println(request.getAttribute("Error_DT"));
            }
            %>
      </td>
    </tr>
    <tr>
      <td width="20%">Thành phố</td>
      <td width="80%" align="left"><label>
        <select name="thanhpho" id="thanhpho">
           <%
                ArrayList<KhuVucPOJO> mathang = (ArrayList<KhuVucPOJO>) request.getAttribute("KhuVucS");
                for(int i=0;i<mathang.size();i++)
                {
                    KhuVucPOJO mh = mathang.get(i);
            %>        

            <option value='<%= mh.getMaKhuVuc() %>'><%= mh.getTenKhuVuc() %></option>
            <%
            }
            %>
        </select>
      </label></td>
    </tr>
    <tr>
      <td width="20%" align="right">&nbsp;</td>
      <td width="80%" align="left">&nbsp;</td>
    </tr>
    <%
    String sss = request.getParameter("ref");
    session.setAttribute("ReferSS", sss);
    String ref = (String) session.getAttribute("ReferSS");
    %>
    <tr>
      <td width="20%" align="left">Người giới thiệu</td>
      <td width="80%" align="left">
          <input type="text" name="txtRefer" readonly="readonly" value="<%if(ref!=null){out.println(ref);}%>" />
      </td>
    </tr>
    <tr>
      <td width="20%" align="right">&nbsp;</td>
      <td width="80%" align="left">&nbsp;</td>
    </tr>
    <tr>
      <td width="20%" align="left">
          Captcha
      </td>
      <td width="80%" align="left">
          <%
          ReCaptcha c = ReCaptchaFactory.newReCaptcha("6Lf2y8kSAAAAABIHkEKoFJnViXHEBjfa_zV-ozsd ", "6Lf2y8kSAAAAAGxWHIqZaLkr4M2IlpGozVkbjmMR ", false);
          out.print(c.createRecaptchaHtml(null, null));
        %>
      </td>
    </tr>
    <tr>
      <td width="20%" align="right">&nbsp;</td>
      <td width="80%" align="left">
          <%
            if (request.getAttribute("Error_capt") != null) {
                out.println(request.getAttribute("Error_capt"));
            }
            %>
      </td>
    </tr>
    <tr>
      <td width="20%" align="right"><label>
        <input type="submit" name="Submit" id="Submit" value="Đăng ký" onClick="return checkForm(form1)"/>
      </label></td>
      <td width="80%" align="left">&nbsp;</td>
    </tr>
  </table>
</form>
      </div>
</div>
<p>&nbsp;</p>
</div>

<div class="cleaner"></div>
</div>